package com.zjkj.mp.service.user.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zjkj.mp.dao.user.UserDao;
import com.zjkj.mp.service.user.UserService;
import com.zjkj.mp.utils.PaginatedResult;
import com.zjkj.mp.vo.MpAuthority;
import com.zjkj.mp.vo.user.MpUser;
import com.zjkj.mp.vo.user.USER_ZT;

@Service
@Transactional(rollbackFor=Exception.class)
public class UserServiceImpl implements UserService {

	@Resource(name="userDaoImpl")
	UserDao userDao;

	public MpUser loginUser(String username, String password) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("username", username);
		map.put("password", password);
		MpUser user = userDao.loginUser(map);
		return user;
	}

	public List<MpAuthority> getQxdmList(String zgdm) {
		// TODO Auto-generated method stub
		return null;
	}

	public void addUser(MpUser user) {
		this.userDao.addUser(user);
	}

	public MpUser findByEmail(String email) {
		return this.userDao.getMpUserByEmail(email);
	}

	public PaginatedResult getUserList(int pageNo, int pageSize,	Map<String, Object> params) {
		 return this.userDao.getUserList(pageNo, pageSize, params);
	}	 

	public void disableUser(int userId) {
		this.userDao.updateUserState(userId,USER_ZT.ZX);
	}

	public MpUser findUserById(int userId) {
		return this.userDao.getMpUser(userId);
	}

	public void updateInfo(MpUser user) {
		this.userDao.updateInfo(user);
	}

	public void addToBlackList(int userId) {
		 this.userDao.updateUserState(userId, USER_ZT.JYZ);
	}

	public void removeFromBalckList(int userId) {
		 this.userDao.updateUserState(userId, USER_ZT.SYZ);
	} 
}